<?php
myauth();

$active['dkp'] = 'active';
if($myinfo['level']!=0)admin_err_page('抱歉,您没有权限访问这个页面');

$actions = array('list','edit','del','addboss');
if(!$action)$action="list";

if($dkpid)
{
    $rs = $db1->query("select * from dkptype where d_id='$dkpid'");
    $dkp = $rs->fetch();
}

if($action=='del')
{
    if(!$dkp)admin_err_page('此DKP分类不存在');
    else
    {
        $db1->exec("delete from dkptype where d_id='$dkp[d_id]'");
        admin_ok_page("删除DKP分类'$dkp[d_name]'成功,请不要刷新此页面以免出现剑类专精效果.", './?admin/dkp');
    }
}



if($action=='list')
{
    $sql = "select * from dkptype order by d_id desc";
    $pager = new ShowPage($db1, 20, $sql);
    $sql = $pager->GetNewSql();
    $rs = $db1->query($sql);
    
    $i = 1;
    while($row = $rs->fetch())
    {
        if($i%2==0)$row['class'] = 'odd';
        $rows[] = $row;
        $i++;
    }

    include template('admin/dkp');
}

if($action=='edit')
{
    
    $opt_yn = array('否','是');
    if($_SERVER['REQUEST_METHOD']=='POST')
    {
        $cache->del('opt_dkp');
        $cache->del('dkps');
        $msg = '';
	$validate = array(
		'd_name' => array('type'=>'string','min_length'=>2, 'max_length'=>30),
	);
	$result = Validate::multiple($_POST, $validate);
        if(!$result['d_name'])admin_err_page('名称为2-30字符之间,请检查填写是否正确');
        $post = array(
            'd_name'=> $d_name,
            'd_cmt' => $d_cmt,
            'd_icon'=> $d_icon,
        );
        $post = array_map("strip_tags", $post);
        if($dkp)
        {
            $db1->UpData($post, 'dkptype', array('d_id'=>$dkp['d_id']));
            admin_ok_page("修改DKP分类'$d_name'成功,请不要刷新此页面以免出现剑类专精效果.", './?admin/dkp');
        }
        else
        {
            $db1->InsertData($post, 'dkptype');
            admin_ok_page("新增DKP分类'$d_name'成功,请不要刷新此页面以免出现剑类专精效果.", './?admin/dkp');
        }

    }
    include template('admin/dkp_edit');
}

if($bossid)
{
    $rs = $db1->query("select * from bosses where b_id='$bossid'");
    $boss = $rs->fetch();
}

if($action=='delbss')
{
    if(!$boss)admin_err_page('此BOSS不存在');
    else
    {
        $db1->exec("delete from bosses where b_id='$boss[b_id]'");
        admin_ok_page("删除BOSS'$dkp[d_name]'成功,请不要刷新此页面以免出现剑类专精效果.", './?admin/dkp/boss');
    }
}

if($action=='boss')
{

    if($_SERVER['REQUEST_METHOD']=='POST')
    {
        $cache->del('opt_dkp');
        $msg = '';
	$validate = array(
            'b_name' => array('type'=>'string'),
            'b_dkp'  => array('type'=>'number','min'=>0),
	);
	$result = Validate::multiple($_POST, $validate);
        if(!$result['b_name'])admin_err_page('请填写BOSS名称');
        $post = array(
            'b_name'=> $b_name,
            'b_cmt' => $b_cmt,
            'b_img' => $b_img,
            'b_dkp' => $b_dkp,
            'dkp_id' => $dkp_id,
            'npc_id' => $npc_id,

        );
        $post = array_map("strip_tags", $post);
        if($boss['b_id'])
        {
            $db1->UpData($post, 'bosses', array('b_id'=>$boss['b_id']));
            admin_ok_page("修改BOSS'$b_name'成功,请不要刷新此页面以免出现剑类专精效果.", './?admin/dkp&action=boss');
        }
        else
        {
            $db1->InsertData($post, 'bosses');
            admin_ok_page("新增BOSS'$b_name'成功,请不要刷新此页面以免出现剑类专精效果.", './?admin/dkp&action=boss');
        }
    }

    

    $cond = "";
    if($dkp)$cond .= " where dkp_id='$dkp[d_id]' ";
    $sql = "select * from bosses $cond order by dkp_id desc,b_id desc";
    $pager = new ShowPage($db1, 20, $sql);
    $sql = $pager->GetNewSql();
    

    $rs = $db1->query($sql);
    $i = 1;
    while($row = $rs->fetch())
    {
        if($i%2==0)$row['css'] = 'odd';
        $rows[] = $row;
        $i++;

    }



    include template('admin/dkp_boss');
}

?>